package display3d.away3d {
	import away3d.cameras.Camera3D;
	import away3d.containers.Scene3D;
	import away3d.containers.View3D;
	import away3d.core.clip.RectangleClipping;

	import flash.display.Sprite;
	
	public class ViewContainer3D extends Sprite
	{
		private var view:View3D;
		private var container:Sprite;
		
		private var _width:Number;
		private var _height:Number;
		
		public function ViewContainer3D(width:Number, height:Number, camera:Camera3D, scene:Scene3D)
		{
			super();
			
			_width = width;
			_height = height;
			container = new Sprite();
			view = new View3D({camera:camera, scene:scene});
			container.addChild(view);
			addChild(container);
			update();
		} 
		
		public function render():void{
			view.render();
		}
		
		public function update():void{
			container.x = _width/2;
			container.y =  _height/2;
			view.clipping = new RectangleClipping({maxX:_width/2, maxY:_height/2, minX:-_width/2, minY:-_height/2});
		}
		
		public function set camera(camera:Camera3D):void{
			view.camera = camera;
		}
		
		public function get camera():Camera3D{
			return view.camera;
		}
		
		public function set scene(scene:Scene3D):void{
			view.scene = scene;
		}
		
		public function get scene():Scene3D{
			return camera.scene;
		}

		override public function get width():Number
		{
			return _width;
		}

		override public function set width(value:Number):void
		{
			_width = value;
			update();
		}

		override public function get height():Number
		{
			return _height;
		}

		override public function set height(value:Number):void
		{
			_height = value;
			update();
		}

	}
}